package com.dragon.modules.yuegou.enums.points;

import com.fasterxml.jackson.annotation.JsonCreator;

import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * 来源
 * 
 * @author pbuilder generated
 *
 */
public enum DetailSource {

	/**
	 * 微信
	 */
	WEICHANT(1, "微信"),
	/**
	 * APP
	 */
	APP(2, "APP"),
	/**
	 * 取消订单
	 */
	CANCEL(3, "取消订单"),
	/**
	 * 小程序
	 */
	MINI(4, "小程序"),
	/**
	 * 后台导入
	 */
	CRM(5, "后台导入"),
	/**
	 * 支付宝
	 */
	ALI(6, "支付宝"),
	/**
	 * 后台编辑
	 */
	EDIT(7, "后台编辑"),
	/**
	 * 注册送礼
	 */
	GIFT(8, "注册送礼"),
	/**
	 * 积分抽奖
	 */
	EXTRACT(9, "积分抽奖"),

	/**
	 * 停车抵扣
	 */
	PARK(10, "停车抵扣");

	/**
	 * 枚举标识
	 */
	private final Integer code;

	/**
	 * 别名
	 */
	private final String alias;

	private DetailSource(Integer code, String alias) {
		this.code = code;
		this.alias = alias;
	}
	
	public Integer getValue() {
		return code;
	}

	/**
	 * 枚举标识
	 * 
	 * @return code
	 */
	public Integer getCode() {
		return code;
	}

	/**
	 * 别名
	 * 
	 * @return alias
	 */
	public String getAlias() {
		return alias;
	}

	/**
	 * 把code转化为费用类型枚举
	 * 
	 * @param code 代码
	 * @return
	 */
	@JsonCreator
	public static DetailSource from(Integer code) {
		if (code == null) {
			return null;
		}
		return CODE_MAP.get(code);
	}

	/**
	 * Code Map for DetailSource
	 */
	private static final Map<Integer, DetailSource> CODE_MAP = Stream.of(DetailSource.values())
			.collect(Collectors.toMap(DetailSource::getCode, e -> e));

}
